package com.hongyuan.coach.ui.member.activity;

import android.os.Bundle;
import android.view.inputmethod.EditorInfo;

import androidx.lifecycle.ViewModelProviders;
import com.hongyuan.coach.R;
import com.hongyuan.coach.base.AppViewModelFactory;
import com.hongyuan.coach.base.CustomActivity;
import com.hongyuan.coach.data.Constants;
import com.hongyuan.coach.data.md5.BaseUtil;
import com.hongyuan.coach.databinding.ActivitySearchMemberBinding;
import com.hongyuan.coach.ui.member.view_mode.SearchMemberViewModel;

import me.tatarka.bindingcollectionadapter2.BR;

public class SearchMemberActivity extends CustomActivity<ActivitySearchMemberBinding, SearchMemberViewModel> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_search_member;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public SearchMemberViewModel initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(SearchMemberViewModel.class);
    }

    @Override
    public void initView() {
        super.initView();

        binding.comBack.setOnClickListener(view -> finish());
        setOnRefresh(binding.refresh,REFRESH_0X3);
        setEnableLoadMore(Constants.GET_COACH_MEMBERS);
        setEnableRefresh(Constants.GET_COACH_MEMBERS);

        //软键盘搜索按钮监听
        binding.searchEt.setOnEditorActionListener((v, actionId, event) -> {
            if (actionId == EditorInfo.IME_ACTION_SEARCH){
                initData();

                return true;
            }
            return false;
        });
    }

    @Override
    public void initData() {
        super.initData();

        viewModel.setParams("type","1");

        if(BaseUtil.isValue(viewModel.searchName.get())){
            viewModel.setParams("search_name",viewModel.searchName.get());
        }
        viewModel.requestData(Constants.GET_COACH_MEMBERS);
    }

}
